package com.tyqx.biz.controller;

import com.ruiyun.jvppeteer.core.Puppeteer;
import com.ruiyun.jvppeteer.core.browser.Browser;
import com.ruiyun.jvppeteer.core.browser.BrowserFetcher;
import com.ruiyun.jvppeteer.core.page.Page;
import com.ruiyun.jvppeteer.options.BrowserOptions;
import com.ruiyun.jvppeteer.options.LaunchOptions;
import com.ruiyun.jvppeteer.options.LaunchOptionsBuilder;

import java.io.IOException;
import java.util.*;
import java.util.concurrent.ExecutionException;


public class TestController {

    public static void main(String[] args) throws IOException, InterruptedException, ExecutionException {
//        String viewBlockUrl = "https://cn.etherscan.com/blocks?ps=100&p="+1;
//
//        System.out.println("aaaa");
//
//        String url = "https://api.huobi.li/market/detail/merged?symbol=ethusdt";
//        String param = "";
//        String basicStats = GetUrlUtil.GetUrl(viewBlockUrl,param);
//        JSONObject basicStatsJson = JSON.parseObject(basicStats);
//        System.out.println(basicStatsJson);
//        System.out.println(123);
//        viewBlockUrl = "https://cn.etherscan.com/blocks?ps=100&p="+1;
//
//        String homeUrl = "https://cn.etherscan.com/";
//
//        List<EthPoolInfo> ethPoolInfoList = JsoupUtil.getEthPoolInfoList(viewBlockUrl,homeUrl);
//
//        System.out.println(ethPoolInfoList);

//        Puppeteer puppeteer = new Puppeteer();
//        //创建下载实例
//        BrowserFetcher browserFetcher = puppeteer.createBrowserFetcher();
//        //下载最新版本的chromuim
//        browserFetcher.download();
//        Browser browser = Puppeteer.launch(false);
//        String version = browser.version();
//        System.out.println(version);

        //设置基本的启动配置,这里选择了‘有头’模式启动
//        ArrayList<String> argList = new ArrayList<>();
//        //自动下载，第一次下载后不会再下载
//        BrowserFetcher.downloadIfNotExist(null);
//        LaunchOptions options = new LaunchOptionsBuilder().withArgs(argList).withHeadless(false).build();
//        argList.add("--no-sandbox");
//        argList.add("--disable-setuid-sandbox");
//        Puppeteer.launch(options);

        //自动下载，第一次下载后不会再下载
//        BrowserFetcher.downloadIfNotExist(null);
//        ArrayList<String> argList = new ArrayList<>();
//        ArrayList<String> argList1 = new ArrayList<>();
//
//        LaunchOptions options = new LaunchOptionsBuilder().withArgs(argList).withIgnoreDefaultArgs(argList1).withHeadless(false).build();
//        argList.add("--no-sandbox");
//        argList.add("--disable-setuid-sandbox");
//        argList1.add("--enable-automation");
////        argList.add("--proxy-server=127.0.0.1:7078");
//
////        Browser browser = Puppeteer.launch(options);
//
//        String webSocketDebuggerUrl= Constants.webSocketDebuggerUrl;
//        Browser browser = Puppeteer.connect(new BrowserOptions(), webSocketDebuggerUrl, null, null, null);
//
//        Page page = browser.newPage();
//        page.goTo("https://cn.etherscan.com/blocks/");
//
//        String content = page.content();
//        System.out.println("==========content===========");
//        System.out.println(content);
//
//        System.out.println("sleep begin");
//        Thread.sleep(5000);
//        System.out.println("sleep end");
//        page.close();
        BrowserFetcher.downloadIfNotExist(null);
        ArrayList<String> argList = new ArrayList<>();
        ArrayList<String> argList1 = new ArrayList<>();

        LaunchOptions options = new LaunchOptionsBuilder().withArgs(argList).withIgnoreDefaultArgs(argList1).withHeadless(false).build();
        argList.add("--no-sandbox");
        argList.add("--disable-setuid-sandbox");
        argList1.add("--enable-automation");
//        argList.add("--proxy-server=127.0.0.1:7078");

//        Browser browser = Puppeteer.launch(options);

        String webSocketDebuggerUrl= "";
        Browser browser = Puppeteer.connect(new BrowserOptions(), webSocketDebuggerUrl, null, null, null);

        Page page = browser.newPage();
        page.goTo("https://cn.etherscan.com/blocks/");

        String content = page.content();
        System.out.println("==========content===========");
        System.out.println(content);

        System.out.println("sleep begin");
        Thread.sleep(5000);
        System.out.println("sleep end");
        page.close();

    }


}
